#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;


void rot(vector<int> &num, int i, int j)
{
    while (i < j) {
	int tmp = num[i];
	num[i] = num[j];
	num[j] = tmp;
	i++;
	j--;
    }
}

int findMin(vector<int> &num)
{
    int lo = 0, hi = num.size()-1;
    while (lo < hi) {
	int mid = lo + (hi-lo)/2;
	if (num[lo] <= num[mid] && num[mid] <= num [hi]) {
	    return num[lo];
	} else if (num[lo] > num[mid]) {
	    hi = mid;
	} else if (num[mid] > num[hi]) {
	    lo = mid +1;
	}
    }
    return num[lo];
}


int main(int argc, char **argv)
{
    int a[] = {1,2,3,4,5,6,7,8,9};
    
    for (int i = 0; i < 10; i++) {
	vector<int> num(a, a + sizeof(a)/sizeof(int));
	int rotate = rand()%num.size();
	rot(num, 0, rotate-1);
	rot(num, rotate, num.size() -1);
	rot(num, 0, num.size()-1);
	for (int j = 0; j < num.size(); j++)
	    cout << num[j] << " ";
	cout << "Min is: " << findMin(num) << endl;
    }
}
